package org.agile2soft.nexoma.expedient.ioc;

import org.agile2soft.nexoma.expedient.controller.DocumentController;
import org.agile2soft.nexoma.expedient.controller.ExpedientController;
import org.agile2soft.nexoma.expedient.controller.ExpedientPhaseController;
import org.agile2soft.nexoma.expedient.controller.ExpedientTypeController;
import org.agile2soft.nexoma.expedient.controller.ExpedientTypePhaseController;
import org.agile2soft.nexoma.expedient.controller.ExpedientTypePhaseExpedientsController;
import org.agile2soft.nexoma.expedient.controller.impl.DocumentControllerImpl;
import org.agile2soft.nexoma.expedient.controller.impl.ExpedientControllerImpl;
import org.agile2soft.nexoma.expedient.controller.impl.ExpedientPhaseControllerImpl;
import org.agile2soft.nexoma.expedient.controller.impl.ExpedientTypeControllerImpl;
import org.agile2soft.nexoma.expedient.controller.impl.ExpedientTypePhaseControllerImpl;
import org.agile2soft.nexoma.expedient.controller.impl.ExpedientTypePhaseExpedientsControllerImpl;
import org.agile2soft.nexoma.expedient.dao.DocumentDAO;
import org.agile2soft.nexoma.expedient.dao.ExpedientDAO;
import org.agile2soft.nexoma.expedient.dao.ExpedientPhaseDAO;
import org.agile2soft.nexoma.expedient.dao.ExpedientTypeDAO;
import org.agile2soft.nexoma.expedient.dao.ExpedientTypePhaseDAO;
import org.agile2soft.nexoma.expedient.dao.ExpedientTypePhaseExpedientsDAO;
import org.agile2soft.nexoma.expedient.dao.hibernate.DocumentDAOImpl;
import org.agile2soft.nexoma.expedient.dao.hibernate.ExpedientDAOImpl;
import org.agile2soft.nexoma.expedient.dao.hibernate.ExpedientPhaseDAOImpl;
import org.agile2soft.nexoma.expedient.dao.hibernate.ExpedientTypeDAOImpl;
import org.agile2soft.nexoma.expedient.dao.hibernate.ExpedientTypePhaseDAOImpl;
import org.agile2soft.nexoma.expedient.dao.hibernate.ExpedientTypePhaseExpedientsDAOImpl;
import org.hibernate.SessionFactory;
import org.springframework.config.java.annotation.Bean;
import org.springframework.config.java.annotation.Configuration;
import org.springframework.config.java.annotation.ExternalBean;
import org.springframework.config.java.annotation.Import;
import org.springframework.config.java.annotation.Lazy;

import br.com.arsmachina.dao.hibernate.ioc.PersistenceConfiguration;

/**
 * Main configuration class for Spring JavaConfig. It just imports the other configuration classes.
 *
 * @author Antonio M. Fernandez Rodriguez
 */
@Configuration(defaultLazy = Lazy.TRUE)
@Import({PersistenceConfiguration.class,ExpedientConfiguration.class})
public class ExpedientConfiguration {

    /**
     * Declares a <code>sessionFactory</code> bean, defined elsewhere.
     *
     * @return a {@link SessionFactory}.
     */
    @ExternalBean
    public SessionFactory sessionFactory() {
        return null;
    }

    /**
     * Declares the <code>expedient </code>dao  bean.
     *
     * @return a {@link Expedient DAO}.
     */
    @Bean
    public ExpedientDAO expedientDAO() {
        return new ExpedientDAOImpl(sessionFactory());
    }

    /**
     * Declares the <code>expedientController</code> bean.
     *
     * @return a {@link ExpedientController}.
     */
    @Bean
    public ExpedientController profilesController() {
        return new ExpedientControllerImpl(expedientDAO());
    }

    /**
     * Declares the <code>expedientType</code> dao bean
     *
     * @return a {@link ExpedientTypeDAO}
     */
    @Bean
    public ExpedientTypeDAO expedientTypeDAO() {
        return new ExpedientTypeDAOImpl(sessionFactory());
    }

    /**
     * Declares the <code> expedientController </code bean.
     *
     * @return a {@link ExpedientTypeController}.
     */
    @Bean
    public ExpedientTypeController expedientTypeController() {
        return new ExpedientTypeControllerImpl(expedientTypeDAO());
    }

    /**
     * Declares the <code>expedientTypePhase</code> dao bean
     *
     * @return a {@link ExpedientTypePhaseDAO}.
     */
    @Bean
    public ExpedientTypePhaseDAO expedientTypePhaseDAO() {
        return new ExpedientTypePhaseDAOImpl(sessionFactory());
    }

    /**
     * Declares the <code> expedientController </code> manager bean.
     *
     * @return a {@link ExpedientTypeController}.
     */
    @Bean
    public ExpedientTypePhaseController expedientTypePhaseController() {
        return new ExpedientTypePhaseControllerImpl(expedientTypePhaseDAO());
    }

    /**
     * Declares the <code>expedientTypePhase</code> dao bean
     *
     * @return a {@link ExpedientPhaseDAO}.
     */
    @Bean
    public ExpedientPhaseDAO expedientPhaseDAO() {
        return new ExpedientPhaseDAOImpl(sessionFactory());
    }

    /**
     * Declares the <code> expedientController </code> manager bean.
     *
     * @return a {@link ExpedientTypeController}.
     */
    @Bean
    public ExpedientPhaseController expedientPhaseController() {
        return new ExpedientPhaseControllerImpl(expedientPhaseDAO());
    }
    /****************/
    /**
     * Declares the <code>expedientTypePhase</code> dao bean
     *
     * @return a {@link ExpedientPhaseDAO}.
     */
    @Bean
    public ExpedientTypePhaseExpedientsDAO expedientTypePhaseExpedientsDAO() {
        return new ExpedientTypePhaseExpedientsDAOImpl(sessionFactory());
    }

    /**
     * Declares the <code> expedientController </code> manager bean.
     *
     * @return a {@link ExpedientTypeController}.
     */
    @Bean
    public ExpedientTypePhaseExpedientsController expedientTypePhaseExpedientsController() {
        return new ExpedientTypePhaseExpedientsControllerImpl(expedientTypePhaseExpedientsDAO());
    }

    /**
     * Declares the <code> document</code> dao bean.
     *
     * @return a {@link DocumentDAO}.
     */
    @Bean
    public DocumentDAO documentDAO() {
        return new DocumentDAOImpl(sessionFactory());
    }

    /**
     * Declares the <code>documentController</code> bean
     *
     * @return a {@link DocumentController}.
     */
    @Bean
    public DocumentController documentController() {
        return new DocumentControllerImpl(documentDAO());
    }

}
